#!/bin/bash

#this shows the diff for modified files 
#and also shows the deleted files as lines beginning with: Only in rsync-backed/

thedir='rsync-backed'  #TODO: make these vars a common file sourced in each script!

#hmm, we don't have sudo and diff when booting from admincd, BUT diff is there inside chroot!
#also colordiff we don't have.

sudo2() {
 cmd="$@"
 if test -x "`which sudo`" ; then
	 sudo ${cmd}
 else
	 ${cmd}
 fi
}

colordiff2() {
	if test -x "`which colordiff`"; then
    colordiff
  else
		tee
	fi
}

sudo2 diff --exclude="${thedir}" -rup "$thedir" ./ 2>/dev/null |grep -E -v '^Only in ./' | colordiff2 | less -R
#^ sudo is needed because gentoo/root for example is inaccessible to normal user!


sudo2 diff --exclude="${thedir}" -rup "$thedir" ./ 2>/dev/null |grep --color=tty "Only in $thedir"
sudo2 diff --exclude="${thedir}" -rup "$thedir" ./ 2>/dev/null |grep --color=tty "^Binary files "


echo "Errors: -------------"
sudo2 diff --exclude="${thedir}" -rup "$thedir" ./ 1>/dev/null
echo "---------------"

sudo2 diff --exclude="${thedir}" -rup "$thedir" ./ 2>&1 1>/dev/null | grep --color=never ": No such file or directory" | cut -d ':' -f 2| sudo2 xargs --no-run-if-empty -n 1 ls -la --color=tty

